namespace CodeConsult.Nordic.nRF8001.ApplicationControlInterface.Commands.DataCommands
{
    public class SetLocalDataCommand : AciCommandBase
    {
        public const byte OpCode = 0x0D;

        public byte ServicePipeNumber { get; set; }
        public byte[] Data { get; set; }

        protected override void EncodeBuffer()
        {
            Error = Error || ServicePipeNumber < 1 || ServicePipeNumber > 62;
            Error = Error || (Data != null && Data.Length > 20);

            if (Error) return;

            var dataLength = Data.Length;
            EncodeBufferWithCommandHeader(OpCode, 1 + dataLength);
            EncodeHelper.SetByte(ServicePipeNumber);
            EncodeHelper.SetBytes(Data);
        }
    }
}
